<script setup>
// 使用pinia
import useStore from '../store'
import { ref } from 'vue'
const { todoList } = useStore()
const inputValue = ref('')
const add = () => {
  if (inputValue.value === '') {
    return
  }
  todoList.addList({
    id: Date.now(),
    name: inputValue.value,
    done: false
  })
  inputValue.value = ''
}
</script>

<template>
  <header class="header">
    <h1>todos</h1>
    <input
      v-model.trim="inputValue"
      class="new-todo"
      placeholder="What needs to be done?"
      autofocus
      @keyup.enter="add"
    />
  </header>
</template>

<style lang="less" scoped></style>
